#!/usr/bin/env python
# coding: utf-8

# In[1]:


#Importing PulP solver
from pulp import *


# In[2]:


#Inputing the Demand points
demand_points=['Port of Newcastle','Port of Hedland','Port of Vienna','Port of Mina','Port of Antwerp','Port of Santos','Port of Montreal','Port of Vancouver','Port of Shanghai','Port of Hamburg_Czeck','Port of Alexandria','Port of Marseille','Port of Hamburg_Germany','Port of Budapest','Port of Jawaharlal Nehru','Port of Tanjung Priok','Port of Bandar Abbas','Port of Umm Qasr','Port of Haifa','Port of Gioia Tauro','Port of Nagoya','Port of Aqaba','Port of Busan','Port of Shuwaikh','Port of Beirut','Port of Manzanillo','Port of Rotterdam','Port of Salalah','Port of Gaza','Port of Gdansk','Port of Doha','Port of King Abdul Aziz','Port of Jeddah','Port of Bratislava','Port of Durban','Port of Algeciras','Port of Gothenburg','Port of Latakia','Port of Kaohsiung','Port of Bangkok','Port of Mersin','Port of Jebel Ali','Port of Immingham','Port of New York','Port of Los Angeles','Port of Hodeidah']


# In[3]:


demand_points


# In[4]:


#Inputing the Supply Points
supply_points=['Port of Buenos Aires','Port of Newcastle','Port of Hedland','Port of Vienna','Port of Antwerp','Port of Santos','Port of Montreal','Port of Vancouver','Port of Shanghai','Port of Hamburg_Czeck','Port of Alexandria','Port of Marseille','Port of Hamburg_Germany','Port of Budapest','Port of Jawaharlal Nehru','Port of Tanjung Priok','Port of Bandar Abbas','Port of Haifa','Port of Gioia Tauro','Port of Nagoya','Port of Aqaba','Port of Busan','Port of Manzanillo','Port of Casablanca','Port of Rotterdam','Port of Salalah','Port of Karachi','Port of Gdansk','Port of Doha','Port of Vladivostok','Port of Novorossiysk','Port of St. Petersburg','Port of King Abdul Aziz','Port of Jeddah','Port of Bratislava','Port of Durban','Port of Algeciras','Port of Gothenburg','Port of Latakia','Port of Kaohsiung','Port of Bangkok','Port of Mersin','Port of Odessa','Port of Jebel Ali','Port of Immingham','Port of New York','Port of Los Angeles','Port of Saigon']


# In[5]:


supply_points


# In[6]:


#Inputing the distances
distance = dict(zip(supply_points,[dict(zip(demand_points, [7087,9900,9783,9420,10946,1078,7874,7508,11098,8105,8607,7282,8105,9669,9312,10113,9112,9691,8747,7606,10707,9083,10985,9646,8704,7342,7827,8169,7282,8820,9355,9476,8921,9771,4596,6504,8275,8631,12452,11538,8606,9168,7877,7248,8833,8382])),
                                   dict(zip(demand_points, [0,3640,11993,8544,13457,7848,10815,6731,5140,13825,9914,11599,13825,11879,6956,4176,8220,8802,9885,10884,4768,9461,5141,8757,9934,6715,13548,7936,9192,14544,8477,8585,8890,11982,6531,11896,12764.72,10099,4693,5436,10095,8290,13598,9689,6466,8351])),
                                   dict(zip(demand_points, [3640,0,9483,6034,10946,8509,13478,7508,3701,11314,7404,9088,11314,9368,4445,1666,5710,6291,7374,8374,4088,6950,3770,6246,7423,8542,11037,5424,6801,12031,5966,6074,6379,9471,5302,9385,11578,7588,3258,3109,7584,5779,11088,12899,7885,5840])),
                                   dict(zip(demand_points, [11993,9483,0,5729,4841,8705,7098,13490,10444,5209,2163,2980,5209,103,5619,8109,5419,6000,2306,2268,11322,2677,10960,5955,2262,10679,4931,4476,2106,5926,5662,5783,3103,0,7426,3279,5474,2167,9880,8664,2142,5475,4982,6839,12171,3642])),
                                   dict(zip(demand_points, [13457,10946,4841,7193,0,6658,3300,11450,11907,426,3665,2339,426,4726,7082,9572,6882,7464,3804,2663,12786,4141,12424,7419,3761,8663,144,5939,3327.94,1143,7125,7247,4567,4829,8066,1561,690,3689,11343,10128,3664,6938,313,3827,10154,5106])),
                                   dict(zip(demand_points, [7848,8509,8705,9662,6658,0,6795,10037,1804,7027,7529,6204,7026,8591,9552,10371,9351,9933,7667,6528,11468,8005,13783,9888,7626,7223,6749,8408,6360,7745,9594,9716,8432,8693,4838,5426,7293,7553,12691,11741,7528,9407,6799,6148,8718,8624])),
                                   dict(zip(demand_points, [10815,13478,7098,9594,3334,6796,0,8696,11673,3669,6196,4871,3669,7258,9614,12104,9414,9808,6336,5195,10961,6672,11234,9794,6020,5899,3391,8471,5165,3878,9657,9778,7099,7361,10468,4093,3425,6220,13875,12660,6195,9470,3435,1729,7389,7364])),
                                   dict(zip(demand_points, [6731,7508,13490,15871,11472,8403,8708,0,4956,11819,12322,10996,11819,13383,9428,7279,10381,10848,12461,11320,4321,12797,4517,10828,12441,2814,11541,10461,10365,12534,10603,10668,13108,13486,13733,10218,12082,12345,5419,7026,12320,10440,11591,7051,1319,11270])),
                                   dict(zip(demand_points, [5140,3701,10444,6882,11907,13268,11673,4956,0,12277,8365,10048,12277,10330,5293,2909,6557,7139,8336,9335,1007,7912,535,7094,8385,6843,11999,6270,7660,12993,6814,6922,7341,10432,8418,10346,12539,8550,597,2872,8546,6627,12049,10547,5688,6802])),
                                   dict(zip(demand_points, [13825,11314,5209,7561,426,7027,3669,11819,12277,0,4033,2708,0,5095,7451,9842,7250,7832,4173,3032,13155,4509,12793,7788,4130,9031,341,6307,3595.7,870,7493,7615,4935,5197,8433,1929,417,4057,11711,10496,4032,7306,448,4195,10522,5475])),
                                   dict(zip(demand_points, [9914,7404,2163,3650,3665,7529,6196,12322,8365,4033,0,1805,4034,2047,3540,6030,3340,3921,370,1092,9243,598,8882,3877,427,9534,3756,2397,242,4750,3583,3704,1024,2150,5347,2103,4298,571,7800,6585,546,3396,3806,5618,11025,1563])),
                                   dict(zip(demand_points, [11599,9088,2980,5332,2339,6204,4871,10996,10048,2708,1805,0,2708,2868,5224,7714,5024,5603,1946,730,10928,2282,10566,5558,1900,8209,2430,4081,1631,3425,5267,5388,2709,2971,7032,778,2971,1830,9485,8270,1806,5080,2481,4293,9700,3245])),
                                   dict(zip(demand_points, [13825,11314,5209,7561,426,7026,3669,11819,12277,0,4034,2708,0,5095,7451,9842,7250,7832,4173,3032,13155,4509,12793,7788,4130,9031,341,6307,3973,870,7493,7615,4935,5197,8433,1929,417,4057,11711,10496,4032,7306,448,4195,10522,5475])),
                                   dict(zip(demand_points, [11879,9368,103,5615,4726,8591,7258,13383,10330,5095,2047,2868,5095,0,5505,7995,5304,5886,2192,2154,11208,2563,10846,5841,2148,10565,4817,4362,1992,5812,5547,5669,2989,102,7312,3165,5360,2052,9766,8550,2028,5360,4868,6728,12056,3528])),
                                   dict(zip(demand_points, [6956,4445,5619,1589,7082,9552,9614,9428,5293,7451,3540,5224,7451,5505,0,3071,1265,1847,3510,4510,6171,3086,5810,1802,3560,12946 ,7173,1143,3243,8167,1522,1630,2515,5607,4714,5521,7715,3725,4727,3513,3720,1335,7224,9036,10104,1977])),
                                   dict(zip(demand_points, [4176,1666,8109,4660,9572,10371,12104,7279,2909,9842,6030,7714,9842,7995,3071,0,4336,4917,6000,7000,3787,5576,3426,4873,6049,8920,9663,4050,5814,10657,4592,4700,5005,8097,5533,8011,10205,6215,2343,1449,6210,4405,9714,11525,7910,4466])),
                                   dict(zip(demand_points, [8220,5710,5419,380,6882,9351,9414,10381,6557,7250,3340,5024,7250,5304,1265,4336,0,581,3310,4310,7435,2886,7074,537,3359,12745,6973,943,2922,7967,355,365,2315,5407,4514,5321,7514,3524,5991,4778,3520,173,7023,8862,11057,1776])), 
                                   dict(zip(demand_points, [9885,7374,2306,3621,3804,7667,6336,12461,8336,4173,370,1946,4173,2192,3510,6000,3310,3891,0,1230,9214,568,8852,3847,81,9673,3894,2367,83,4889,3553,3674,995,2293,5318,2242,4436,237,7770,6556,233,3366,3944,5756,11048,1534])), 
                                   dict(zip(demand_points, [10884,8374,2268,4620,2663,6528,5195,11320,9335,3032,1092,730,3032,2154,4510,7000,4310,4891,1230,0,10213,1568,9852,4847,1189,8533,2754,3367,1336,3749,4553,4674,1994,2256,6317,1102,3295,1116,8771,7555,1091,4366,2805,4617,10024,2533])),
                                   dict(zip(demand_points, [4768,4088,11322,7759,12786,11468,10961,4321,1007,13155,9243,10928,13155,11208,6171,3787,7435,8017,9214,10213,0,8790,612,7972,9263,6131,12877,7148,8308,13871,7692,7800,8219,11310,9308,11224,13418,9428,1498,3750,9424,7505,12927,9835,4992,7680])),
                                   dict(zip(demand_points, [9461,6950,2677,3197,4141,8005,6672,12797,7912,4509,598,2282,4509,2563,3086,5576,2886,3467,568,1568,8790,0,8428,3423,618,10011,4231,1943,486,5224,3423,3250,571,2665,4894,2579,4774,783,7346,6132,778,2942,4282,6104,11501,1110])),
                                   dict(zip(demand_points, [5141,3770,10960,7398,12424,13783,11234,4517,535,12793,8882,10566,12793,10846,5810,3426,7074,7655,8852,9852,612,8428,0,7611,8901,6404,12515,6786,8020,13509,7330,7438,7857,10949,8939,10863,13056,9066,1137,3388,9062,7143,12565,10108,5249,7318])),
                                   dict(zip(demand_points, [6715,8542,10679,13061,8663,7223,5899,2814,6843,9031,9534,8209,9031,10565,12946 ,8920,12745,13332,9673,8533,6131,10011,6404,13286,9631,0,8736,11791,8088,9730,12977,13099,10419,10681,10919,7413,9277,9541,7268,8865,9516,12790,8787,4237,1490,10974])),
                                   dict(zip(demand_points, [12117,9606,3500,5852,1592,5205,4247,9881,10568,1862,2325,999,1862,3386,5742,8232,5542,6123,2463,1323,11445,2800,11084,6079,2421,7192,1682,4599,2178,2676,5785,5906,3227,3489,6612,221,2224,2348,10003,8788,2324,5598,1732,3544,8701,3766])),
                                   dict(zip(demand_points, [13548,11037,4931,7284,144,6749,3391,11541,11999,341,3756,2430,341,4817,7173,9663,6973,7555,3894,2754,12877,4231,12515,7510,3852,8736,0,6030,3335,1058,7216,7338,4658,4920,8156,1652,606,3780,11434,10219,3755,7029,282,3918,10245,5197])),
                                   dict(zip(demand_points, [7936,5424,4476,1253,5939,8408,8471,10461,6270,6307,2397,4081,6307,4362,1143,4050,943,1524,2367,3367,7148,1943,6786,1480,2416,11791,6030,0,2086,7025,1186,1307,1372,4464,3571,4378,6418,2582,5704,4490,2577,999,6081,7930,11137,833])),
                                   dict(zip(demand_points, [7544,5033,5502,1000,6966,9435,9498,9882,5881,7334,3423,5108,7334,5388,589,3659,676,1258,3394,4393,6759,2970,6397,1213,3443,12818,7057,1027,2952,8051,933,1041,2399,5491,4597,5405,7598,3608,5315,4101,3604,746,7107,8945,14319,1860])),
                                   dict(zip(demand_points, [14544,12031,5926,8277,1143,7745,3878,12534,12993,870,4750,3425,870,5812,8167,10657,7967,8548,4889,3749,13871,5224,13509,8504,4847,9730,1058,7025,4119,0,8213,8334,5654,5915,9152,2649,452,4775,12430,11215,4751,8025,1166,4316,11242,6190])),
                                   dict(zip(demand_points, [8477,5966,5662,140,7125,9594,9657,10603,6814,7493,3583,5267,7493,5547,1522,4592,355,490,3553,4553,7692,3423,7330,421,3602,12977,7216,1186,3139,8213,0,219,2558,5650,4757,5564,7757,3767,6248,5034,3763,187,7267,9392,11279,2019])),
                                   dict(zip(demand_points, [5520,4348,11544,7981,13008,14355,10879,4140,1118,13376,9465,11148,13376,11430,6393,4009,7657,8239,9435,10435,1031,9011,583,8194,9485,6049,13098,7370,8522,14092,7914,8022,8441,11532,9517,11446,13640,9650,1720,3971,9645,7727,13149,9753,4885,7902])),
                                   dict(zip(demand_points, [11406,8893,1312,5139,4251,8117,6782,12907,9854,4619,1572,2392,4619,1197,5029,7519,4829,5410,1715,1678,10732,2087,10371,5366,1672,10103,4342,3886,1295,5338,5072,5193,2680,2513,6839,2689,4885,1577,9290,8074,1552,4885,4392,6246,11613,3052])),
                                   dict(zip(demand_points, [15051,12540,6435,8787,1652,8252,4385,13036,13502,1377,5259,3933,1377,6321,8677,11166,8476,9058,5398,4258,14380,5735,14018,9013,5355,10225,1568,7533,4545,646,8719,8841,6161,6423,9660,3156,960,5283,12938,11722,5258,8532,1674,4824,11600,6700])), 
                                   dict(zip(demand_points, [8585,6074,5783,108,7247,9716,9778,10668,6922,7615,3704,5388,7615,5669,1630,4700,365,274,3674,4674,7800,3250,7438,203,3724,13099,7338,1307,3203,8334,219,0,2680,5771,4878,5685,7879,3889,6356,5142,3885,389,7388,9222,11344,2141])), 
                                   dict(zip(demand_points, [8890,6379,3103,2626,4567,8432,7099,13108,7341,4935,1024,2709,4935,2989,2515,5005,2315,2897,995,1994,8219,571,7857,2852,1044,10419,4658,1372,828,5654,2558,2680,0,3092,4323,3006,5200,1209,6775,5561,1205,2371,4708,6521,11927,539])), 
                                   dict(zip(demand_points, [11982,9471,42,5717,4829,8693,7361,13486,10432,5197,2150,2971,5197,102,5607,8097,5407,5988,2293,2256,11310,2665,10949,5944,2250,10681,4920,4464,2243,5915,5650,5771,3092,0,7415,3267,5460,2155,9868,8653,2130,5463,4970,6830,12158,3631])), 
                                   dict(zip(demand_points, [6531,5302,7426,4824,8066,4838,10468,13733,8418,8433,5347,7032,8433,7312,4714,5533,4514,5095,5318,6317,9308,4894,8939,5050,5367,10919,8156,3571,7346,9152,4757,4878,4323,7415,0,6834,8698,5534,7930,6941,5530,4572,8207,9902,12410,3786])), 
                                   dict(zip(demand_points, [11896,9385,3279,5631,1561,5426,4093,10218,10346,1929,2103,778,1929,3165,5521,8011,5321,5902,2242,1102,11224,2579,10863,5858,2200,7413,1652,4378,2004,2649,5564,5685,3006,3267,6834,0,2195,2127,9782,8567,2102,5377,1703,3515,8922,3545])), 
                                   dict(zip(demand_points, [12764.72,11578,5474,7825,690,7293,3425,12082,12539,417,4298,2971,417,5360,7715,10205,7514,8096,4436,3295,13418,4774,13056,8051,4394,9277,606,6418,3775.72,452,7757,7879,5200,5460,8698,2195,0,4323,11978,10763,4299,7573,714,3864,10789,5739])), 
                                   dict(zip(demand_points, [10099,7588,2167,3835,3689,7553,6220,12345,8550,4057,571,1830,4057,2052,3725,6215,3524,4106,237,1116,9428,783,9066,4061,196,9541,3780,2582,248,4775,3767,3889,1209,2155,5534,2127,4323,0,7986,6770,89,3580,3830,5642,11049,1748])), 
                                   dict(zip(demand_points, [4693,3258,9880,6316,11343,12691,13875,5419,597,11711,7800,9485,11711,9766,4727,2343,5991,6573,7770,8771,1498,7346,1137,6528,7819,7268,11434,5704,7144,12430,6248,6356,6775,9868,7930,9782,11978,7986,0,2307,7981,6063,11485,10972,6129,6236])), 
                                   dict(zip(demand_points, [5436,3109,8664,5102,10128,11741,12660,7026,2872,10496,6585,8270,10496,8550,3513,1449,4778,5359,6556,7555,3750,6132,3388,5315,6605,8865,10219,4490,6341,11215,5034,5142,5561,8653,6941,8567,10763,6770,2307,0,6766,4847,10269,12081,7730,5022])), 
                                   dict(zip(demand_points, [10095,7584,2142,3831,3664,7528,6195,12320,8546,4032,546,1806,4032,2028,3720,6210,3520,4102,233,1091,9424,778,9062,4057,191,9516,3755,2577,316,4751,3763,3885,1205,2130,5530,2102,4299,89,7981,6766,0,3576,3804,5617,11024,1744])), 
                                   dict(zip(demand_points, [11223,7812,1003,4957,4069,7935,6601,12727,9674,4437,1390,2211,4437,889,4847,7337,4647,5228,1533,1496,10552,1905,10190,5184,1490,9922,4160,3704,1181,5156,4890,5011,2332,992,6657,2508,4704,1395,9110,7894,1370,4703,4210,6064,11432,2871])), 
                                   dict(zip(demand_points, [8290,5779,5475,327,6938,9407,9470,10440,6627,7306,3396,5080,7306,5360,1335,4405,173,606,3366,4366,7505,2942,7143,562,3415,12790,7029,999,2975,8025,187,389,2371,5463,4572,5377,7573,3580,6063,4847,3576,0,7080,8918,11116,1832])), 
                                   dict(zip(demand_points, [13598,11088,4982,7334,313,6799,3435,11591,12049,448,3806,2481,448,4868,7224,9714,7023,7605,3944,2805,12927,4282,12565,7560,3903,8787,282,6081,3399,1166,7267,7388,4708,4970,8207,1703,714,3830,11485,10269,3804,7080,0,3968,10295,5247])), 
                                   dict(zip(demand_points, [9689,12899,6839,9168,3827,6148,1729,7051,10547,4195,5618,4293,4195,6728,9036,11525,8862,9417,5756,4617,9835,6104,10108,9392,5715,4237,3918,7930,5196,4316,9392,9222,6521,6830,9902,3515,3864,5642,10972,12081,5617,8918,3968,0,5734,7105])), 
                                   dict(zip(demand_points, [6466,7885,12171,14552,10154,8718,7389,1319,5688,10522,11025,9700,10522,12056,10104,7910,11057,11524,11048,10024,4992,11501,5249,11504,11122,1490,10245,11137,9280,11242,11279,11344,11927,12158,12410,8922,10789,11049,6129,7730,11024,11116,10295,5734,0,12465])), 
                                   dict(zip(demand_points, [4876,2659,8528,4964,9991,11334,12523,6829,1997,10360,6448,8133,10360,8413,3376,993,4640,5221,6418,7418,2881,5994,2520,5177,6467,15842,10082,4353,6368,11079,4896,5004,5423,8516,6577,8430,10626,6633,1434,870,6628,4709,10133,11986,593,4884]))]))


# In[7]:


distance


# In[8]:


#Inputing the HSS Demand
HSS_demand=dict(zip(demand_points, [679896.1202,7944513.963,451438.2583,1315356,2477523.01,273567,4287443.085,788679.4984,30165986,8550037.087,34398,11198470.95,13828820.54,1574223,42473614.68,6405001.649,114513,7644,1323,1528639.242,67063280.61,1438542,48622717.26,2384735.454,21168,2313192,758000.0875,147,0,1126123.844,2363907,3455247.453,935642.5472,4207923.707,1045905,7289438.043,769775.2501,8379,3908861.42,14594487.96,6312425.199,185367,6374577.388,34451279.01,16230723.48,1470]))


# In[9]:


HSS_demand


# In[10]:


#Inputing the HSS Supply
HSS_supply=dict(zip(supply_points, [866877.0693,173144.9288,821571.1032,1773459.805,459052.6648,5883513.708,524041.6326,1760443.821,174549236.3,679520.2497,2083553.909,1090975.226,7439233.572,33423.521,36697735.91,1158608.705,12288124.19,55964.6881,4143159.023,16087392.42,26211.20016,12220325.9,3391773.351,94405.71585,1188401.541,345449.5083,581771.9193,1617356.557,857772.4871,7688763.821,3750207.916,3793349.172,587030.7966,330012.7357,828258.7044,1062704.488,2506427.832,1020455.739,6807.982054,3982299.048,742013.6356,5765276.992,81761.53917,715075.2826,1240430.535,9068509.538,6320971.137,21581546.32])) 


# In[11]:


HSS_supply


# In[12]:


# Set Problem Variables
prob = LpProblem("Transportation", LpMinimize)


# In[13]:


prob


# In[14]:


# Set Problem Variables
routes = [(i,j) for i in supply_points for j in demand_points]


# In[15]:


routes


# In[16]:


# Decision Variables
X = LpVariable.dicts("ShipmentAmount",(supply_points, demand_points),0)


# In[17]:


X


# In[18]:


# Objective Function
prob += sum(X[i][j]*distance[i][j] for (i,j) in routes)


# In[19]:


prob


# In[20]:


# Constraints
for j in demand_points:
    prob += sum(X[i][j] for i in supply_points) >= HSS_demand[j]
    
prob


# In[21]:


# Constraints
for i in supply_points:
    prob += sum(X[i][j] for j in demand_points) == HSS_supply[i]
prob


# In[22]:


prob.solve()

print("Status:", LpStatus[prob.status])

for v in prob.variables():
    if v.varValue > 0:
        print(v.name, "=", v.varValue)

print("Total kilogram_miles =", value(prob.objective))


# In[ ]:




